package com.zhumei.keyscale.util;

import java.util.regex.*;

public class StringUtils
{
    public static String getMoney(String s) {
        final Matcher matcher = Pattern.compile("(\\d+\\.\\d+)").matcher(s);
        if (matcher.find()) {
            if (matcher.group(1) == null) {
                return "";
            }
            s = matcher.group(1);
        }
        else {
            final Matcher matcher2 = Pattern.compile("(\\d+)").matcher(s);
            if (!matcher2.find()) {
                return "";
            }
            if (matcher2.group(1) == null) {
                return "";
            }
            s = matcher2.group(1);
        }
        return s;
    }
    
    public static String setPriceTYpe(final String s, final String s2, final int n) {
        if (s.contains(".")) {
            if (s2.equals(".")) {
                return s;
            }
            if (s.length() - s.indexOf(".") > 2) {
                return s;
            }
            final StringBuilder sb = new StringBuilder();
            sb.append(s);
            sb.append(s2);
            return sb.toString();
        }
        else {
            if (s.length() == 0 && s2.equals(".")) {
                return "0.";
            }
            if (n == 1) {
                final StringBuilder sb2 = new StringBuilder();
                sb2.append(s);
                sb2.append(s2);
                return sb2.toString();
            }
            if (s2.equals(".")) {
                return s;
            }
            String string = s;
            if (s.length() < 2) {
                final StringBuilder sb3 = new StringBuilder();
                sb3.append(s);
                sb3.append(s2);
                string = sb3.toString();
            }
            return string;
        }
    }
}
